package main

import (
	"fmt"
	"net"
	"net/http"
	"net/rpc"
	"time"
)

type Server struct {
}

type Req struct {
	NumOne int
	NumTwo int
}

type Res struct {
	Num int
}

// 必须是两个参数 一个req 接收  一个是res 响应返回
func (s *Server) Add(req Req, res *Res) error {
	fmt.Println("server add")
	time.Sleep(time.Second * 5)
	res.Num = req.NumOne + req.NumTwo
	return nil
}

func main() {
	fmt.Println("server")
	rpc.Register(new(Server))
	rpc.HandleHTTP()
	l, e := net.Listen("tcp", ":8888")
	if e != nil {
		fmt.Println(e)
	}
	fmt.Println("server rpc")
	http.Serve(l, nil)
}
